home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
print
/
890ps.arc
/
NETWARE.C
< prev
next >
Wrap
Text File
|
1989-12-31
|
11KB
|
637 lines
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#ifdef __OS2_MT__
#include <process.h>
#endif
#include <netware.h>
#define swap(val) ((val<<8)+(val>>8))
#define swapd(val) ((val<<24)+((val&0xFF00)<<8)+((val&0xFF0000L)>>8)+(val>>24))
#define initbuf(buf) memset(&buf,0,sizeof(buf));buf._len = sizeof(buf)-sizeof(buf._len) /* initialize buffer length */
byte NetWare(word func, void *req, void *rep)
{
union REGS i_reg,o_reg;
struct SREGS sreg;
i_reg.h.ah = func;
i_reg.x.si = FP_OFF(req);
i_reg.x.di = FP_OFF(rep);
#if (defined M_I86SM) | (defined M_I86MM)
sreg.ds = _DS;
sreg.es = _ES;
#else
sreg.ds = FP_SEG(req);
sreg.es = FP_SEG(rep);
#endif
#ifdef __OS2_MT__
Lock();
#endif
int86x(0x21,&i_reg,&o_reg,&sreg);
#ifdef __OS2_MT__
Unlock();
#endif
return(o_reg.h.al);
}
byte ChangeBinderyObjectPassword(const char *name, word type,
const char *oldpass, const char *newpass)
{
struct {
word _len;
byte _func;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
byte _oldpasslen;
char _oldpass[OBJPASSMAXLEN];
byte _newpasslen;
char _newpass[OBJPASSMAXLEN];
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x40;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
req._oldpasslen = OBJPASSMAXLEN;
strcpy(req._oldpass,oldpass);
req._newpasslen = OBJPASSMAXLEN;
strcpy(req._newpass,newpass);
return(NetWare(0xE3,&req,&rep));
}
byte DeleteBinderyObject(const char *name, word type)
{
struct {
word _len;
byte _func;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x33;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
return(NetWare(0xE3,&req,&rep));
}
byte CreateBinderyObject(const char *name, word type, const char *password,
byte security, byte flags)
{
struct {
word _len;
byte _func;
byte _flags;
byte _security;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
} req;
struct {
word _len;
} rep;
word res;
initbuf(req);
initbuf(rep);
req._func = 0x32;
req._flags = flags;
req._security = security;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
res = NetWare(0xE3,&req,&rep);
if ((res==0) && (strlen(password)!=0)) {
if ((res=ChangeBinderyObjectPassword(name,type,"",password))!=0) {
DeleteBinderyObject(name,type);
};
};
return(res);
}
byte LoginToFileServer(const char *name, word type, const char *password)
{
struct {
word _len;
byte _func;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
byte _passwordlen;
char _password[OBJPASSMAXLEN];
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x14;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
req._passwordlen = OBJPASSMAXLEN;
strcpy(req._password,password);
return(NetWare(0xE3,&req,&rep));
}
byte CreateQueue(const char *name, word type, byte dir, const char *path,
dword *id)
{
struct {
word _len;
byte _func;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
byte _dir;
byte _pathlen;
char _path[118];
} req;
struct {
word _len;
dword _id;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x64;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
req._dir = dir;
req._pathlen = 118;
strcpy(req._path,path);
res = NetWare(0xE3,&req,&rep);
if (id!=NULL) {
*id = swapd(rep._id);
}
return(res);
}
byte AllocPermanentDirectoryHandle(char drive, byte dir, const char *path,
byte *handle, byte *rights)
{
struct {
word _len;
byte _func;
byte _dir;
byte _drive;
byte _pathlen;
char _path[255];
} req;
struct {
word _len;
byte _handle;
byte _rights;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x12;
req._dir = dir;
req._drive = drive;
req._pathlen = 255;
strcpy(req._path,path);
res=NetWare(0xE2,&req,&rep);
if (handle!=NULL) {
*handle = rep._handle;
}
if (rights!=NULL) {
*rights = rep._rights;
}
return res;
}
byte EnterLoginArea(byte locals, const char *path)
{
struct {
word _len;
byte _func;
byte _locals;
byte _pathlen;
char _path[255];
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x0A;
req._locals = locals;
req._pathlen = 255;
strcpy(req._path,path);
return NetWare(0xE3,&req,&rep);
}
byte GetBinderyObjectID(const char *name, word type, dword *id)
{
struct {
word _len;
byte _func;
word _type;
byte _namelen;
char _name[OBJNAMEMAXLEN];
} req;
struct {
word _len;
dword _id;
word _type;
char _name[OBJNAMEMAXLEN+1];
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x35;
req._type = swap(type);
req._namelen = OBJNAMEMAXLEN;
strcpy(req._name,name);
res=NetWare(0xE3,&req,&rep);
if (id!=NULL) {
*id = swapd(rep._id);
}
return(res);
}
byte AttachQueueServerToQueue(dword id)
{
struct {
word _len;
byte _func;
dword _id;
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x6F;
req._id = swapd(id);
return(NetWare(0xE3,&req,&rep));
}
byte DetachQueueServerFromQueue(dword id)
{
struct {
word _len;
byte _func;
dword _id;
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x70;
req._id = swapd(id);
return(NetWare(0xE3,&req,&rep));
}
void ConvertJobInfo(QueueJobInfoStruct *out, const QueueJobInfoStruct *in)
{
if ((out!=NULL) && (in!=NULL)) {
memcpy(out,in,sizeof(QueueJobInfoStruct));
out->_ClientID = swapd(in->_ClientID);
out->_TargetID = swapd(in->_TargetID);
out->_JobNumber = swap(in->_JobNumber);
out->_JobType = swap(out->_JobType);
out->_ServerID = swapd(out->_ServerID);
}
}
byte ServiceQueueJobAndOpenFile(dword id, word type,
QueueJobInfoStruct *info)
{
struct {
word _len;
byte _func;
dword _id;
word _type;
} req;
struct {
word _len;
QueueJobInfoStruct _info;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x71;
req._id = swapd(id);
req._type = swap(type);
res=NetWare(0xE3,&req,&rep);
ConvertJobInfo(info,&rep._info);
return(res);
}
byte FinishServicingQueueJobAndFile(dword id, word job, dword charge)
{
struct {
word _len;
byte _func;
dword _id;
word _job;
dword _charge;
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x72;
req._id = swapd(id);
req._job = swap(job);
req._charge = swapd(charge);
return(NetWare(0xE3,&req,&rep));
}
byte ReadQueueCurrentStatus(dword id, byte *status, byte *jobs, byte *servers,
dword sid[], byte stations[], byte *mserver)
{
struct {
word _len;
byte _func;
dword _id;
} req;
struct {
word _len;
dword _id;
byte _status;
byte _jobs;
byte _servers;
dword _sid[25];
byte _stations[25];
byte _mserver;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x66;
req._id = swapd(id);
res=NetWare(0xE3,&req,&rep);
if (status!=NULL) {
*status = rep._status;
}
if (jobs!=NULL) {
*jobs = rep._jobs;
}
if (servers!=NULL) {
*servers = rep._servers;
}
if (sid!=NULL) {
for (res=0;res<25;res++) {
sid[res] = swapd(rep._sid[res]);
}
res = 0;
}
if (stations!=NULL) {
for (res=0;res<25;res++) {
stations[res] = rep._stations[res];
}
res = 0;
}
if (mserver!=NULL) {
*mserver = rep._mserver;
}
return(res);
}
byte AbortServicingQueueJobAndFile(dword id, word job)
{
struct {
word _len;
byte _func;
dword _id;
word _job;
} req;
struct {
word _len;
} rep;
initbuf(req);
initbuf(rep);
req._func = 0x73;
req._id = swapd(id);
req._job = swap(job);
return(NetWare(0xE3,&req,&rep));
}
byte Logout(void)
{
union REGS i_regs, o_regs;
i_regs.h.ah = 0xD7;
#ifdef __OS2_MT__
Lock();
#endif
int86(0x21,&i_regs,&o_regs);
#ifdef __OS2_MT__
Unlock();
#endif
return(0);
}
byte ReadQueueJobEntry(dword id, word job, QueueJobInfoStruct *info,
char jdesc[], byte client[])
{
struct {
word _len;
byte _func;
dword _id;
word _job;
} req;
struct {
word _len;
QueueJobInfoStruct _info;
char _jdesc[50];
byte _client[152];
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x6C;
req._id = swapd(id);
req._job = swap(job);
res=NetWare(0xE3,&req,&rep);
ConvertJobInfo(info,&rep._info);
if (jdesc!=NULL) {
memcpy(jdesc,&rep._jdesc,sizeof(rep._jdesc));
}
if (client!=NULL) {
memcpy(client,&rep._client,sizeof(rep._client));
}
return(res);
}
byte ReadPrintJobInfo(dword id, word job, PrintJobClientStruct *client)
{
byte res;
res=ReadQueueJobEntry(id,job,NULL,NULL,(byte *) client);
if (client!=NULL) {
client->_Copies = swap(client->_Copies);
client->_Flags = swap(client->_Flags);
client->_Lines = swap(client->_Lines);
client->_Chars = swap(client->_Chars);
}
return(res);
}
byte GetQueueJobList(dword id, word *count, word jobs[], word *max)
{
struct {
word _len;
byte _func;
dword _id;
} req;
struct {
word _len;
word _count;
word _jobs[250];
word _max;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x6B;
req._id = swapd(id);
res=NetWare(0xE3,&req,&rep);
if (count!=NULL) {
*count = swap(rep._count);
}
if (jobs!=NULL) {
for (res=0;res<250;res++) {
jobs[res] = swap(rep._jobs[res]);
}
res = 0;
}
if (max!=NULL) {
*max = swap(rep._max);
}
return(res);
}
byte GetQueueJobsFileSize(dword id, word job, dword *size)
{
struct {
word _len;
byte _func;
dword _id;
word _job;
} req;
struct {
word _len;
dword _id;
word _job;
dword _size;
} rep;
byte res;
initbuf(req);
initbuf(rep);
req._func = 0x78;
req._id = swapd(id);
req._job = swap(job);
res=NetWare(0xE3,&req,&rep);
if (size!=NULL) {
*size = swapd(rep._size);
}
return(res);
}